class CameraMoveScript extends Laya.Script {
    protected lastMouseX: number;
    protected lastMouseY: number;
    protected yawPitchRoll = new Laya.Vector3();
    protected resultRotation = new Laya.Quaternion();
    protected tempRotationZ = new Laya.Quaternion();
    protected tempRotationX = new Laya.Quaternion();
    protected tempRotationY = new Laya.Quaternion();
    protected isMouseDown: Boolean;
    protected rotaionSpeed: number = 0.00006;
    protected sensitivity:number=0.1;
    protected sensitivity_sphere:number=0.6;
    protected slider_valuedown:number;

    protected scene: Laya.Scene;
    protected camera: Laya.Camera;

    constructor() {
        super();
    }


    public _initialize(owner: Laya.Sprite3D): void {
        super._initialize(owner);
        Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.mouseDown);
        Laya.stage.on(Laya.Event.MOUSE_UP, this, this.mouseUp);
        Laya.stage.on(Laya.Event.MOUSE_OUT, this, this.mouseOut);

        this.camera = owner as Laya.Camera;
    }

    public _update(state: Laya.RenderState): void {
        super._update(state);
     //   if (!DataInfoInstance.getInstance().start_state) return ;
        this.updateCamera(state.elapsedTime);
    }

    protected mouseDown(e: Laya.Event): void {
     //   console.log("down",DataInfoInstance.getInstance().ui_imgState);
        if(DataInfoInstance.getInstance().ui_imgState)
        {
            DataInfoInstance.getInstance().ui_ImgBegin.scale(0,0);
            DataInfoInstance.getInstance().ui_imgState=false;
            DataInfoInstance.getInstance().UIManage(uiView.all,true);
            DataInfoInstance.getInstance().PlaySoundOnce(SoundName.button);
            DataInfoInstance.getInstance().txt1.changeText(DataInfoInstance.getInstance().txt1Number.toString());
            DataInfoInstance.getInstance().play_pause=false;
            DataInfoInstance.getInstance().start_state=true;
            DataInfoInstance.getInstance().showiconTxt();
        }
        this.camera.transform.localRotation.getYawPitchRoll(this.yawPitchRoll);
        this.lastMouseX = Laya.stage.mouseX;
        this.lastMouseY = Laya.stage.mouseY;
        this.cuurx=Laya.stage.mouseX;
        this.cuury=Laya.stage.mouseY;
        this.isMouseDown = true;
    }

    protected mouseUp(e: Laya.Event): void {
        this.lastMouseX = Laya.stage.mouseX;
        this.lastMouseY = Laya.stage.mouseY;
        this.isMouseDown = false;
    }

    protected mouseOut(e: Laya.Event): void {
        this.isMouseDown = false;
    }
    protected cuurx=0;
    protected cuury=0;
    protected move_speed:number=0;
    protected updateCamera(elapsedTime: number): void {
        if(!this.isMouseDown)return;
        if (!isNaN(this.lastMouseX) && !isNaN(this.lastMouseY)) {
          //  var scene = this.owner.scene;
            Laya.KeyBoardManager.hasKeyDown(87) && this.camera.moveForward(-0.002 * elapsedTime);//W
            Laya.KeyBoardManager.hasKeyDown(83) && this.camera.moveForward(0.002 * elapsedTime);//S
            Laya.KeyBoardManager.hasKeyDown(65) && this.camera.moveRight(-0.002 * elapsedTime);//A
            Laya.KeyBoardManager.hasKeyDown(68) && this.camera.moveRight(0.002 * elapsedTime);//D
            Laya.KeyBoardManager.hasKeyDown(81) && this.camera.moveVertical(0.002 * elapsedTime);//Q
            Laya.KeyBoardManager.hasKeyDown(69) && this.camera.moveVertical(-0.002 * elapsedTime);//E

            if (this.isMouseDown&&(this.cuurx!=Laya.stage.mouseX||this.cuury!=Laya.stage.mouseY)) {
              // DataInfoInstance.getInstance().shlider.seths_value(this.slider_valuedown+(Laya.stage.mouseX - this.lastMouseX)*this.sensitivity);
             //  DataInfoInstance.getInstance().fatherobj.transform.rotate(new Laya.Vector3(0, 0,(Laya.stage.mouseX - this.cuurx)*this.sensitivity_sphere), true, false);
               this.move_speed++;
            //   if (this.move_speed>2){
            //      //.   PlaySphere.getInstance().movestye(Laya.stage.mouseX - this.cuurx);
            //        this.move_speed=0;
            //    }
                ControlFunc.getInstance().setMove(Laya.stage.mouseX - this.cuurx,Laya.stage.mouseY - this.cuury);
               this.cuurx=Laya.stage.mouseX;
               this.cuury=Laya.stage.mouseY;
            }
            else if(this.isMouseDown&&(this.cuurx==Laya.stage.mouseX||this.cuury==Laya.stage.mouseY)){this.move_speed=0;}

        }
        
    }


}